package com.itqf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.itqf.mapper.WarehouseProductMapper;
import com.itqf.pojo.WarehouseProduct;
import com.itqf.service.WarehouseProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/7
 * @Time: 下午3:40
 */
@Service
public class WarehouseProductServiceImpl implements WarehouseProductService {

    @Resource
    private WarehouseProductMapper warehouseProductMapper;

    @Transactional
    @LcnTransaction //fenbushi
    @Override
    public int update(long pId,int c) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("product_id",pId);
        WarehouseProduct wareHouseProduct =  warehouseProductMapper.selectOne(queryWrapper);
        wareHouseProduct.setCurrentCnt(wareHouseProduct.getCurrentCnt()+c);

        int i = warehouseProductMapper.update(wareHouseProduct,queryWrapper);


        return i;
    }
}
